<?php


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class VrSellHouse extends Model
{
    use HasFactory;

    protected $fillable = ['house_name','address','developers','building_types','flat_type','house_type',
    'area','price','floor_plan','traffic_condition','surrounding_facility','sales_link','created_at','updated_at'
    ];

    protected $casts = [
        'house_name' =>'string',
        'address' =>'string',
        'developers' =>'string',
        'area'=>'double',
        'price' =>'float'
        ];

    //多条件搜索分页
    public static function getSecharvr($params, $limit, $offset)
    {
        $data['data']= self::where('is_del',0)->when($params, function ($query) use ($params) {
            if (isset($params['house_name']) && !empty($params['house_name'])) {
                $query->where('house_name', 'like', '%' . $params['house_name'] . '%');
            }
            if (isset($params['price']) && !empty($params['price'])) {
                $query->Where('price', '>',$params['price']);
            }
        })->offset($offset)->limit($limit)->get();//offset是偏移量; //mit展示每页条数

        $data['total'] =(int)self::where('is_del',0)->when($params, function ($query) use ($params) {
            if (isset($params['house_name']) && !empty($params['house_name'])) {
                $query->where('house_name', 'like', '%' . $params['house_name'] . '%');
            }
            if (isset($params['price']) && !empty($params['phone'])) {
                $query->Where('price', '>',$params['price']);
            }
        })->count();//offset是偏移量; //mit展示每页条数;

        $data['limit'] =(int)$limit;
        $data['page']  =  (int)$params['page'];
        return $data;
    }


    //详情
    static function detailVr($where)
    {
        return self::where($where)->first();
    }

    //添加vr
    static function createVr(array $param)
    {
        return self::create($param);
    }

    //修改vr
    static function whereUpdateVr($where, $update)
    {
        return self::where($where)->update($update);
    }
}
